package com.ruoyi.web.controller.erpbase;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.system.domain.TreeSelectStocks;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Stocks;
import com.ruoyi.system.service.IStocksService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库管理Controller
 * 
 * @author he
 * @date 2025-09-16
 */
@Api(tags = "仓库接口")
@RestController
@RequestMapping("/system/stocks")
public class StocksController extends BaseController
{
    @Autowired
    private IStocksService stocksService;

    /**
     * 查询仓库管理列表
     */
    @ApiOperation("查询仓库列表信息")
    @PreAuthorize("@ss.hasPermi('system:stocks:list')")
    @GetMapping("/list")
    public TableDataInfo list(Stocks stocks)
    {
        startPage();
        List<Stocks> list = stocksService.selectStocksList(stocks);
        return getDataTable(list);
    }


    /**
     * 查询仓库管理列表
     */
    @ApiOperation("查询仓库下拉框信息")
//    @PreAuthorize("@ss.hasPermi('system:stocks:list')")
    @PostMapping("/getStocksInfoList")
    public TableDataInfo getStocksInfoList(@RequestParam(value = "paramName", required = false) String paramName)
    {
//        startPage();
        List<Stocks> list = stocksService.getStocksInfoList(paramName);
        return getDataTable(list);
    }

    @ApiOperation("获取仓库信息树结构")
    @PostMapping("/getStocksTree")
    public AjaxResult getStocksTree(@RequestParam(value = "paramName", required = false) String paramName)
    {
//        startPage();
        List<TreeSelectStocks> list = stocksService.getStocksTree(paramName);
        return success(list);
    }

    /**
     * 导出仓库管理列表
     */
    @ApiOperation("导出仓库信息")
    @PreAuthorize("@ss.hasPermi('system:stocks:export')")
    @Log(title = "仓库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Stocks stocks)
    {
        List<Stocks> list = stocksService.selectStocksList(stocks);
        ExcelUtil<Stocks> util = new ExcelUtil<Stocks>(Stocks.class);
        util.exportExcel(response, list, "仓库管理数据");
    }

    /**
     * 获取仓库管理详细信息
     */
    @ApiOperation("获取仓库详细信息")
    @PreAuthorize("@ss.hasPermi('system:stocks:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stocksService.selectStocksById(id));
    }

    /**
     * 新增仓库管理
     */
    @ApiOperation("新增仓库信息")
    @PreAuthorize("@ss.hasPermi('system:stocks:add')")
    @Log(title = "仓库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Stocks stocks)
    {
        return toAjax(stocksService.insertStocks(stocks));
    }

    /**
     * 修改仓库管理
     */
    @ApiOperation("修改仓库信息")
    @PreAuthorize("@ss.hasPermi('system:stocks:edit')")
    @Log(title = "仓库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Stocks stocks)
    {
        return toAjax(stocksService.updateStocks(stocks));
    }

    /**
     * 删除仓库管理
     */
    @ApiOperation("删除仓库信息")
    @PreAuthorize("@ss.hasPermi('system:stocks:remove')")
    @Log(title = "仓库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stocksService.deleteStocksByIds(ids));
    }
}
